package com.cheer.enums;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.File;
import java.util.Arrays;
import java.util.Optional;

@NoArgsConstructor
@AllArgsConstructor
public enum ResourceEnum {

    IMAGE("1", "image", "jpg"),
    DOC("2", "doc", "doc,docx"),
    OTHER("3", "other", "");

    @Getter
    private String typeCode;
    @Getter
    private String pathName;
    @Getter
    private String fileType;


    public static ResourceEnum getByTypeCode(String typeCode){

        ResourceEnum[] values = ResourceEnum.values();
        Optional<ResourceEnum> first = Arrays.stream(values).filter(resourceEnum -> typeCode.equals(resourceEnum.getTypeCode())).findFirst();

        return first.orElse(null);
    }

    /**
     * 获取文件路径并创建文件
     * @param basePath
     * @param fileName
     * @return
     */
    public String filePath(String basePath, String fileName){
        return basePath + File.separator + this.getPathName() + File.separator + fileName;
    }




}
